﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace WeChat.Controls
{
    public class ImageButton : Button
    {
        public static readonly DependencyProperty ImageProperty = DependencyProperty.Register("Image", typeof(Geometry), typeof(ImageButton), new PropertyMetadata(null, OnPropertyChanged));

        /// <summary>
        /// 图标
        /// </summary>
        public Geometry Image
        {
            get { return (Geometry)GetValue(ImageProperty); }
            set { SetValue(ImageProperty, value); }
        }

        public static readonly DependencyProperty ImageWidthProperty = DependencyProperty.Register("ImageWidth", typeof(double), typeof(ImageButton), new PropertyMetadata(12.0));

        /// <summary>
        /// 图标宽度
        /// </summary>
        public double ImageWidth
        {
            get { return (double)GetValue(ImageWidthProperty); }
            set { SetValue(ImageWidthProperty, value); }
        }

        public static readonly DependencyProperty ImageHeightProperty = DependencyProperty.Register("ImageHeight", typeof(double), typeof(ImageButton), new PropertyMetadata(12.0));

        /// <summary>
        /// 图标高度
        /// </summary>
        public double ImageHeight
        {
            get { return (double)GetValue(ImageHeightProperty); }
            set { SetValue(ImageHeightProperty, value); }
        }

        public static readonly DependencyProperty ImageForegroundProperty = DependencyProperty.Register("ImageForeground", typeof(Brush),
            typeof(ImageButton), new PropertyMetadata(Brushes.Gray, OnPropertyChanged));

        /// <summary>
        /// 图片颜色
        /// </summary>
        public Brush ImageForeground
        {
            set { SetValue(ImageForegroundProperty, value); }
            get { return (Brush)GetValue(ImageForegroundProperty); }
        }

        private static void OnPropertyChanged(DependencyObject dependency, DependencyPropertyChangedEventArgs args)
        {
            ImageButton button = dependency as ImageButton;
            if (args.Property.Name.Equals("ImageForeground"))
                button.ImageForeground = (Brush)args.NewValue;
            else if (args.Property.Name.Equals("Image"))
                button.Image = (Geometry)args.NewValue;
        }
    }
}
